package com.gnerv.rabbitmq.agent.command;

import com.gnerv.rabbitmq.agent.model.entity.Node;
import com.gnerv.rabbitmq.agent.tools.ExecTools;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
public class ConnectionCommand extends AbstractRabbitmqctlCommand {

    public ConnectionCommand(Node node){
        super();
        setNode(node);
    }

    public static ConnectionCommand build(Node node){
        return new ConnectionCommand(node);
    }

    public ExecTools.ExecResult listConnections() {
        List<String> listExchanges = Lists.newArrayList();
        listExchanges.add("list_connections");
        return run(listExchanges);
    }


    public ExecTools.ExecResult closeAllConnections(String vhost) {
        List<String> listExchanges = Lists.newArrayList();
        listExchanges.add("close_all_connections");
        listExchanges.add("-p");
        listExchanges.add(vhost);
        return run(listExchanges);
    }

    public ExecTools.ExecResult closeConnection(String connectionpid) {
        List<String> listExchanges = Lists.newArrayList();
        listExchanges.add("close_connection");
        listExchanges.add(connectionpid);
        listExchanges.add("go way");
        return run(listExchanges);
    }

}
